﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using com.nm.library.Excels;
using System.ComponentModel.Composition;
using com.nm.Helper;

namespace VerticaAPI.Export
{
    /// <summary>
    /// 补货需求单
    /// </summary>
    [Export(typeof(ExcelImport))]
    public class DwSuppleRound: ExcelImport
    {
        public override ExcelImportType Type => ExcelImportType.SUPPLY;
        public override Dictionary<string, ImportVerify> DictFields => _dictFields;
        /// <summary>
        /// Excel字段映射
        /// </summary>
        private static readonly Dictionary<string, ImportVerify> _dictFields = new List<ImportVerify> {
            new ImportVerify{ ColumnName="店铺名称",FieldName="ShopName",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,200,true,true)},
            new ImportVerify{ ColumnName="仓库编号",FieldName="StockID",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,30,true,true)},
            new ImportVerify{ ColumnName="商品代码",FieldName="MaterialID",DataType=typeof(string),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,30,true,true)},
            new ImportVerify{ ColumnName="尺码",FieldName="SizeName" ,DataType=typeof(string),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,10,false,false)},
            new ImportVerify{ ColumnName="需求数量",FieldName="SuppleQty",DataType=typeof(int),VerifyFunc =(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,10,true,true)},
            new ImportVerify{ ColumnName="库存数量",FieldName="Qty",DataType=typeof(int),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,10,false,true) },
            new ImportVerify{ ColumnName="实际补货数量",FieldName="can_supply_qty",DataType=typeof(int),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,10,true,true) },
            new ImportVerify{ ColumnName="补货时间",FieldName="SuppleDate" ,DataType=typeof(string),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,30,false,false)},
            new ImportVerify{ ColumnName="补货轮次",FieldName="Round" ,DataType=typeof(int),VerifyFunc=(e,extra)=> ExcelImportHelper.GetCellMsg(e.CellValue,e.ColName,10,false,false)},
           }.ToDictionary(e => e.ColumnName, e => e);

        public override object SaveImportData(DataTable dt, Dictionary<string, object> extraInfo, int userId)
        {
            throw new NotImplementedException();
        }
        /// <summary>
        /// 获取导出的数据
        /// </summary>
        /// <param name="Keys">查询筛选条件</param>
        /// <returns>Datatable</returns>
        public override DataTable GetExportData(string Keys)
        {
            var db=new DwSupplyRoundHandler();
            var strWhere = string.Empty;
            if (!string.IsNullOrWhiteSpace(Keys))
            {
                strWhere = Keys;                
            }
            return db.ReturnDwSuppleRound(strWhere);
        }
    }
}
